package com.xiaoma.service;

import com.rabbitmq.client.Channel;
import entity.MyMessage;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * @Author: xiaoma
 * @Date: 2021/7/9 15:19
 * @description:
 */
//@Service
//@RabbitListener(queues = {"xiaoma-queue"})
public class MessageService {
    @RabbitHandler
    public void recieveMessage(Message message, MyMessage myMesaage, Channel channel)  {
        System.out.println("接受到消息："+myMesaage);
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        try {
            //收货 手动ack，非批量模式
            channel.basicAck(deliveryTag,false);
            //退货
//            channel.basicNack(deliveryTag,false,false);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
